package com.xsq.util;

import java.util.Map;

import android.annotation.SuppressLint;

import com.POSD.controllers.PrinterController;

@SuppressLint("SimpleDateFormat")
public class PrintUtils {

	
	//消费后打印的发票
	public static void printConsumeInfo(PrinterController printerController,String printTitle, Map<String, Object> info, String winname, String printcode) {

		try {

			String logicno = String.valueOf(info.get("logicno"));
			String jy_time = String.valueOf(info.get("consumetime"));// yyyyMMddHHmmss

			String header_title = printTitle;  //;"鑫三强消费统计单据";
			String winname_title = "窗口号：" + winname;
			String posno_title = "设备号：" + logicno;
			String consume_time = "交易时间：" + jy_time.substring(0, 4)+"-"+jy_time.substring(4, 6)+"-"+jy_time.substring(6,8)  + " " + jy_time.substring(8,10)+":"+jy_time.substring(10,12)+":"+jy_time.substring(12);;

			String flowid = "流水号：" + String.valueOf(info.get("flowid"));
			
			String tab_head = "用户工号  交易金额(元) 余额(元)";
			//String usercode = "用户编号：" + String.valueOf(info.get("usercode"));
			//String jy_money = "扣款金额：" + StringFormatUtils.getFormatJe(""+Double.parseDouble(String.valueOf(info.get("amount")))/100);
			//String ky_money = "可用余额：" + StringFormatUtils.getFormatJe(""+Double.parseDouble(String.valueOf(info.get("kyMoney")))/100);
			
			String tab_detail = ""+String.valueOf(info.get("usercode"))+"   "+StringFormatUtils.getFormatJe(""+Double.parseDouble(String.valueOf(info.get("amount")))/100,5)+"   "+StringFormatUtils.getFormatJe(""+Double.parseDouble(String.valueOf(info.get("kyMoney")))/100,10)+"";

			byte[] head_title_bytes = printcode.equals("0") ? header_title.getBytes("GB2312") : header_title.getBytes();
			byte[] win_bytes = printcode.equals("0") ? winname_title.getBytes("GB2312") : winname_title.getBytes();
			byte[] pos_bytes = printcode.equals("0") ? posno_title.getBytes("GB2312") : posno_title.getBytes();
			byte[] consumeTime_bytes = printcode.equals("0") ? consume_time.getBytes("GB2312") : consume_time.getBytes();

			byte[] flowid_bytes = printcode.equals("0") ? flowid.getBytes("GB2312") : flowid.getBytes();
			byte[] tab_head_bytes = printcode.equals("0") ? tab_head.getBytes("GB2312") : tab_head.getBytes();
			byte[] tab_detail_bytes = printcode.equals("0") ? tab_detail.getBytes("GB2312") : tab_detail.getBytes();
			//byte[] usercode_bytes = printcode.equals("0") ? usercode.getBytes("GB2312") : usercode.getBytes();
			//byte[] jy_money_bytes = printcode.equals("0") ? jy_money.getBytes("GB2312") : jy_money.getBytes();
			//byte[] ky_money_bytes = printcode.equals("0") ? ky_money.getBytes("GB2312") : ky_money.getBytes();

			printerController.PrinterController_reset();
			printerController.PrinterController_PrinterLanguage(0);
			printerController.PrinterController_Take_The_Paper(1);// 打印机走纸
			printerController.PrinterController_Print("--------------------------------".getBytes());
			printerController.PrinterController_Linefeed();// 换行
			printerController.PrinterController_Linefeed();// 换行
			printerController.PrinterController_Linefeed();// 换行

			// 标题加粗居中
			printerController.PrinterController_Font_Bold();
			printerController.PrinterController_Set_Center();

			if (printcode.equals("0")) {
				// 2016内核
				printerController.PrinterController_PrinterLanguage(2);
			} else if (printcode.equals("1")) {
				// 2017内核
				printerController.PrinterController_PrinterLanguage(0);
			}

			printerController.PrinterController_Print(head_title_bytes);// 标题
			printerController.PrinterController_Linefeed();// 换行
			printerController.PrinterController_Linefeed();// 换行

			printerController.PrinterController_Font_Normal_mode();// 字体正常模式
			printerController.PrinterController_Set_Left();// 靠左

			printerController.PrinterController_Print(win_bytes);// 窗口信息
			printerController.PrinterController_Linefeed();
			printerController.PrinterController_Print(pos_bytes);// 设备号
			printerController.PrinterController_Linefeed();
			printerController.PrinterController_Print(flowid_bytes);// 流水号
			printerController.PrinterController_Linefeed();
			
			
			printerController.PrinterController_Print(tab_head_bytes);//表头
			printerController.PrinterController_Linefeed();
			printerController.PrinterController_Print(tab_detail_bytes);//表内容
			printerController.PrinterController_Linefeed();
			/*
			printerController.PrinterController_Print(usercode_bytes);// 用户编号
			printerController.PrinterController_Linefeed();
			printerController.PrinterController_Print(jy_money_bytes);// 交易金额
			printerController.PrinterController_Linefeed();
			printerController.PrinterController_Print(ky_money_bytes);// 可用余额
			printerController.PrinterController_Linefeed();
			*/

			printerController.PrinterController_Print(consumeTime_bytes);// 交易时间
			printerController.PrinterController_Linefeed();

			printerController.PrinterController_Linefeed();
			printerController.PrinterController_PrinterLanguage(0);
			printerController.PrinterController_Print("--------------------------------".getBytes());

			printerController.PrinterController_Linefeed();// 换行
			printerController.PrinterController_Take_The_Paper(1);

		} catch (Exception e) {
			e.printStackTrace();
		}

	}
}
